package com.kecheng.action;

import java.io.File;
import java.io.IOException;

import com.kecheng.dao.GuanzhuDao;
import com.kecheng.pojo.Guanzhu;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * 后台关注回复的增删改查
 * @author yunxin
 *
 */
@Action(value = "guanzhu", results = {
		@Result(name = "find", location = "/admin/weixin/guanzhu.jsp"),
		@Result(name = "guanzhu", location = "/w/guanzhu.jsp"),
})
@AllowedMethods(value = {("regex:.*")})
public class GuanzhuAction extends BaseAction {

	private File file;
	private String fileFileName;
	private String fileContentType;
	private Guanzhu guanzhu;
	@Autowired
	private GuanzhuDao guanzhuDao;

	@Transactional(readOnly = false)
	public String update() throws IOException {
		if (file == null) {
			Guanzhu guanzhu1 = guanzhuDao.find();
			guanzhu.setImg(guanzhu1.getImg());
		} else {
			guanzhu.setImg("http://"+peizhi.getNetName()+"/" + compressFile(file, fileFileName, null));
		}
		dao.update(guanzhu);
		return find();
	}

	public String find() {
		guanzhu = guanzhuDao.find();
		return "find";
	}

	public String find1() {

		guanzhu = guanzhuDao.find();

		return "guanzhu";
	}

	public Guanzhu getGuanzhu() {
		return guanzhu;
	}

	public void setGuanzhu(Guanzhu guanzhu) {
		this.guanzhu = guanzhu;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

}
